﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ServerFrame;
using Servertest.Logic.Login;
using Protocol;

namespace Servertest
{
    /// <summary>
    /// 消息处理中心，负责消息的分发处理
    /// </summary>
    
    public class HandlerCenter:AbsMessageCenter
    {
        IMessageHendler login;

        public HandlerCenter() {
            login = new LoginHandler();
        }
        public override void OnClientConnected(MyToken token)
        {
            Console.WriteLine("有客户端连接"+token.socket.AddressFamily);
        }
        public override void OnClientClose(MyToken token, string error)
        {
            Console.WriteLine(error);

            login.OnClientClose(token, error);
        }

        //public override void OnClientConnected(MyToken token)
        //{

        //}

        public override void OnMessageReceive(MyToken token, TransModel model)
        {
            if (model == null) { return; }

            //
            //判断model.type,根据协议分发model
            //switch()
            switch (model.type)
            {
                case GameProtocol.Login:
                    login.OnMessageReceive(token, model);
                    break;
                default:
                    break;
            }
        }
    }
}
